﻿Imports DTO
Imports System.Data.OleDb
Public Class CKhoiLopDAO

    Public Function LayDanhSachKhoiLop() As List(Of CKhoiLopDTO)
        Dim cnn As OleDbConnection = CDaTaProviderDAO.ConnectDB()
        cnn.Open()
        Dim _strdskhoilop = "select MaKhoiLop,TenKhoiLop,SoLuongLop from KHOILOP"
        Dim _cmd As New OleDbCommand(_strdskhoilop, cnn)
        Dim _reader As OleDbDataReader = _cmd.ExecuteReader()
        Dim _danhsachkhoilop As New List(Of CKhoiLopDTO)
        While _reader.Read()
            Dim _KLdto As New CKhoiLopDTO()
            _KLdto.MaKhoiLop = _reader.GetInt32(0)
            _KLdto.TenKhoiLop = _reader.GetString(1)
            _KLdto.SoLuongLop = _reader.GetInt32(2)
            _danhsachkhoilop.Add(_KLdto)
        End While
        cnn.Close()
        Return _danhsachkhoilop
    End Function

    Public Function ThemKhoiLop(ByVal _KLdto As CKhoiLopDTO) As Integer
        Dim cnn As OleDbConnection = CDaTaProviderDAO.ConnectDB()
        cnn.Open()
        Dim _strthemkhoilop = "insert into KHOILOP(TenKhoiLop,SoLuongLop) values('" + _KLdto.TenKhoiLop + "'," + _KLdto.SoLuongLop.ToString() + ")"
        Dim _cmd As New OleDbCommand(_strthemkhoilop, cnn)
        Dim _kt As Integer = _cmd.ExecuteNonQuery()
        cnn.Close()
        Return _kt
    End Function

    Public Function CapNhatKhoiLop(ByVal _KLdto As CKhoiLopDTO) As Integer
        Dim cnn As OleDbConnection = CDaTaProviderDAO.ConnectDB()
        cnn.Open()
        Dim _strcapnhatkl = "update KHOILOP set TenKhoiLop='" + _KLdto.TenKhoiLop + "',SoLuongLop=" + _KLdto.SoLuongLop.ToString() + " where MaKhoiLop=" + _KLdto.MaKhoiLop.ToString() + ""
        Dim _cmd As New OleDbCommand(_strcapnhatkl, cnn)
        Dim _kt As Integer = _cmd.ExecuteNonQuery()
        cnn.Close()
        Return _kt
    End Function
End Class
